package com.zto.sch.advance.aqs;

import java.util.concurrent.CountDownLatch;

/**
 * @program: sch-diy-parent
 * @description:
 * @author: sch
 * @create: 2021-01-11 17:41
 **/
public class Main_CountDownLatch {
    public static int m = 0;
    private static CountDownLatch countDownLatch = new CountDownLatch(100);
    private static MyLock_AQS myLock_aqs = new MyLock_AQS();

    public static void main(String[] args) throws InterruptedException {
        Thread[] threads = new Thread[100];
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread(() -> {
                myLock_aqs.lock();
                for (int j = 0; j < 100; j++) {
                    m++;
                }
                myLock_aqs.lock();

                countDownLatch.countDown();
            });
        }

        for (Thread thread : threads) {
            thread.start();
        }

        countDownLatch.await();

        System.out.println(m);
    }
}
